package exam.alibaba;


import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        int maxNum = Integer.MIN_VALUE;
        int minNum = Integer.MAX_VALUE;
        int minIndex = -1;
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
            if(nums[i] > maxNum)
                maxNum = nums[i];
            if(nums[i] < minNum){
                minIndex = i;
                minNum = nums[i];
            }
        }
        if(n == 2)
            System.out.println(0);
        if(minIndex == n - 1)
            System.out.println(maxNum - (nums[n - 2] + minNum));
        System.out.println(maxNum - (nums[minIndex + 1] + minNum));
    }

   /* public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        if(n == 2)
            System.out.println(0);
        long count = Integer.MAX_VALUE;
        for (int i = 0; i < n - 1; i++) {
            long temp1 = nums[i];
            long temp2 = nums[i + 1];
            nums[i] = temp1 + temp2;
            nums[i + 1] = temp1 + temp2;
            count = Math.min(count, fun(nums));
            nums[i] = temp1;
            nums[i+1] = temp2;
        }
        System.out.println(count);
    }
    private static long fun(long []nums){
        long maxNum = Integer.MIN_VALUE;
        long minNum = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] > maxNum)
                maxNum = nums[i];
            if (nums[i] < minNum) {
                minNum = nums[i];
            }
        }
        return maxNum - minNum;
    }*/

}
